<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title></title>
    </head>
    <body>

        
        <?php
        
        
        $a = array("teste", "teste2");
        echo ( in_array("teste4", $a) ? "True" : "False" );
        /*
          //error_reporting(0);


          $url = file_get_contents("http://www-usr.inf.ufsm.br/~fcampagnolo/");

          //$xml_site = simplexml_load_file("http://www-usr.inf.ufsm.br/~fcampagnolo/");
          //$result_site = $xml_site->xpath("body");
          //print_r($result_site);

          //$url = file_get_contents("sainf2013.html");
          $xml_sainf = simplexml_load_file("sainf2013.html");
          $result_sainf = $xml_sainf->xpath("//div/*");
          //print_r($result_sainf);

          foreach($result_sainf as $str){
          echo "Achei SAINF: $str <br/>";
          }

          /* $ch = curl_init();

          curl_setopt($ch, CURLOPT_URL, "http://www-usr.inf.ufsm.br/~fcampagnolo/");
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_HEADER, 1);
          curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

          $pagina = curl_exec($ch); */

        //$xml = simplexml_load_file("http://www-usr.inf.ufsm.br/~fcampagnolo/");


        /* $xml = simplexml_load_file("html_teste.xml");
          $result = $xml->xpath("body");
          print_r($result);


          $xml = simplexml_load_file("html_teste2.html");
          $result = $xml->xpath("//li/*");
          foreach($result as $str){
          echo "Achei: $str <br/>";
          }

          //print_r($result);


          //$result = $xml->xpath('/body');


          //echo $xml->body; */


        /* $file = "html_teste2.html";
          $depth = array();

          function startElement($parser, $name, $attrs) {
          global $depth;

          if (!isset($depth[$parser])) {
          $depth[$parser] = 0;
          }

          for ($i = 0; $i < $depth[$parser]; $i++) {
          echo "  ";
          }
          echo "$name - <b>linha".xml_get_current_line_number($parser)."</b><br/> ";
          $depth[$parser]++;
          }

          function endElement($parser, $name) {
          global $depth;
          $depth[$parser]--;
          }

          $xml_parser = xml_parser_create();
          xml_set_element_handler($xml_parser, "startElement", "endElement");
          if (!($fp = fopen($file, "r"))) {
          die("could not open XML input");
          }

          while ($data = fread($fp, 4096)) {
          if (!xml_parse($xml_parser, $data, feof($fp))) {
          die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
          }
          }
          xml_parser_free($xml_parser); */


// Create a new DOMDocument instance
// Load the XML
//        $dom->loadXML('
//<fruits>
// <apples>
//  <apple>braeburn</apple>
//  <apple>granny smith</apple>
// </apples>
// <pears>
//  <pear>conference</pear>
// </pears>
//</fruits>
//');
        /*        $dom = new DOMDocument;

          $dom->loadHTMLFile("html_teste2.html");
          //$dom->loadHTMLFile("www.inf.ufsm.br/~fcampagnolo");
          // Print XPath for each element
          //        foreach ($dom->getElementsByTagName('*') as $node) {
          //            echo $node->getNodePath() . " - Linha " . $node->getLineNo() . "<br/>";
          //        }
          ## XPATH com DOM
          $xpath = new DOMXPath($dom);

          $query = '//li';

          $entries = $xpath->query($query);

          echo "<h1>XPATH</h1>";
          foreach ($entries as $entry) {
          //            echo "Found {$entry->nodeValue} - <b>Linha: ". $entry->getLineNo() ."</b> - <i>Teste: ".$entry->getAttribute('class')."</i><br/>";
          echo "Found {$entry->nodeValue} - <b>Linha: " . $entry->getLineNo() . "</b> - <i>Teste: " . $entry->nodeName . "/" . $entry->getAttribute('class') . "</i><br/>";
          }
         */


        // Include the library
        include('simple_html_dom.php');

//// Create DOM from URL or file
//$html = file_get_html('http://www.google.com/');
//
//// Find all images 
//foreach($html->find('img') as $element) 
//       echo $element->src . '<br>';
//
//// Find all links 
//foreach($html->find('a') as $element) 
//       echo $element->href . '<br>';
//####################### teste com simple DOM HTML
//        $html = file_get_html('http://www.inf.ufsm.br/~fcampagnolo');
//        echo "<hr>";
//// Find all images 
//        foreach ($html->find('a') as $element) {
//            echo $element->tag . '<hr>';
//            echo $element->outertext . '<hr>';
//            echo $element->innertext . '<hr>';
//            echo $element->plaintext . '<hr>';
//            echo 'T '.$element->nodeValue . '<hr>';
//            echo $element . '<hr>';
//            echo '<br/>';
//            echo '<br/>';
//            echo '<br/>';
//            
//        }
//        
//        echo $html->plaintext."<br/><br/><br/>";
//        
//        echo file_get_html('http://www.google.com/')->plaintext;
//        $dom = new DOMDocument;
//
//        $dom->loadHTMLFile("www.inf.ufsm.br/~fcampagnolo");
//        //$dom->loadHTMLFile("www.inf.ufsm.br/~fcampagnolo");
//        // Print XPath for each element
////        foreach ($dom->getElementsByTagName('a') as $node) {
////            echo $node->getNodePath() . " - Linha " . $node->getLineNo() . "<br/>";
////        }
//
//        echo $dom->src . '<br>';
//
//        echo '<hr>';
//        ## XPATH com DOM
//        print_r($dom);
//          $xpath = new DOMXPath($dom);
//
//          $query = '//li';
//
//          $entries = $xpath->query($query);
//
//          echo "<h1>XPATH</h1>";
//          foreach ($entries as $entry) {
//          //            echo "Found {$entry->nodeValue} - <b>Linha: ". $entry->getLineNo() ."</b> - <i>Teste: ".$entry->getAttribute('class')."</i><br/>";
//          echo "Found {$entry->nodeValue} - <b>Linha: " . $entry->getLineNo() . "</b> - <i>Teste: " . $entry->nodeName . "/" . $entry->getAttribute('class') . "</i><br/>";
//          }
//        
        ?>
        <br/>
        <hr >
        <br/>
        <?php
        // a new dom object
        $dom = new domDocument;

// load the html into the object
        $dom->loadHTML('<html>
    <body>
        <div id="mango">
            This is the mango div. It has some text and a form too.
            <form>
                <input type="text" name="first_name" value="Yahoo" />
                <input type="text" name="last_name" value="Bingo" />
            </form>
             
            <table class="inner">
                <tr><td>Happy</td><td>Sky</td></tr>
            </table>
        </div>
        <br>
        <table id="data" class="outer">
            <tr><td>Happy</td><td>Sky</td></tr>
            <tr><td>Happy</td><td>Sky</td></tr>
            <tr><td>Happy</td><td>Sky</td></tr>
            <tr><td>Happy</td><td>Sky</td></tr>
            <tr><td>Happy</td><td>Sky</td></tr>
        </table>
    </body>
</html>');



// discard white space
        $dom->preserveWhiteSpace = false;
        //print_r($dom);
        //get element by id
        $mango_div = $dom->getElementsByTagName('table');
        foreach ($mango_div as $f) {
            print_r($f);
            echo '<br/>';
            echo '<br/>';
            echo "teste " . $f->nodeName;
            echo "teste " . $f->getLineNo();
            echo '<br/>';
            echo '<br/>';
        }

        echo '<br>' . $dom->getElementById('mango')->tagName . '<br>';


        $mango_div = $dom->getElementById('mango');
        print_r($mango_div);
        foreach ($mango_div as $t) {
            print_r($t);
            echo '<br/>';
            echo '<br/>';
            echo "teste2 ";
            echo '<br/>';
            echo '<br/>';
        }

//        if (!mango_div) {
//            die("Element not found");
//        }
//
//        echo "element found";
//        echo $mango_div;
//        echo $mango_div->nodeValue;
        ?>
        <!--        <h1>curl_init</h1>
                <textarea cols="70" rows="10"><?php echo $pagina; ?></textarea>
                <h1>file_get_contents</h1>
                <textarea cols="70" rows="10"><?php echo $url; ?></textarea>-->


        <!--        ###################################################
                LENDO CSS
                ###################################################-->

        <?php
        echo "<hr><h1>Teste CSS</h1>";
        include_once './src/Class_parser_css.php';
        
        $oCSS = new CSS();
        
        $oCSS->parse_file("style.css");
        var_dump($oCSS);
       // print_r($oCSS);

        
        echo "<h3>Parse CSS file</h3>";

        foreach ($oCSS->get_css() as $prop => $attrs) {
            print_r($attrs);
            print_r($prop);
            foreach ($attrs as $attr => $value) {

                echo "$attr: $value";
            }
        }
        ?>


    </body>
</html>